from multiprocessing import Queue, Process
from time import sleep


def write(q):
    name = ["a", "b", "I am congyu", 500]
    for item in name:
        if not q.full():
            print(f"开始写入：{item}")
            q.put(item)
            sleep(1)


def reader(q):
    for item in range(q.qsize()):
        print(f"读取第{item}值： {q.get()}")
        sleep(1)


if __name__ == "__main__":
    queue = Queue()
    pw = Process(target=write, args=(queue,))
    pr = Process(target=reader, args=(queue,))
    print("写入启动")
    pw.start()
    pw.join()
    print(f"写入结束,现有元素总数: {queue.qsize()}")

    print("读取启动")
    pr.start()
    pr.join()
    print(f"读取结束,现有元素总数: {queue.qsize()}")
